<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    身份证正面
    <input type="file" id="fronID" accept="image/*">
    身份证反面
    <input type="file" id="endID" accept="image/*">

    <div>
        <button onclick="upload()">身份证上传</button>
    </div>


    <div style="margin-top: 10px;">
        身份证图片转base64
        <input type="file" id="sfzID" accept="image/*">
        <button onClick="logFn()">打印</button>
    </div>
    <div style="margin-top: 10px;">
        营业执照转base64
        <input type="file" id="yyzzID" accept="image/*">
        <button onClick="logFn2()">打印2</button>
    </div>
    <div style="margin-top: 10px;">
        行驶证转base64
        <input type="file" id="xszID" accept="image/*">
        <button onClick="logFn3()">打印3</button>
    </div>

    <div style="margin-top: 10px;">
        <input id="messageID" type="number" placeholder="请输入手机号">
        <button onClick="sendMessage()">发送短信验证码</button>
    </div>
    <!-- <script src="https://cdn.bootcdn.net/ajax/libs/axios/1.7.2/axios.js"></script> -->
    <script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
    <script>
        // 没有登录的情况下请求数据
        axios.get('http://localhost:3004/fyx/workerorder/list').then(res => {
            console.log(res.data)
        })

        let token = ''

        const sendMessage = () => {
            var messageID = document.getElementById('messageID');
            if(!messageID.value || messageID.value.length!==11) {
                alert('手机号格式不对')
                return;
            }
            axios({
                        method: 'post',
                        url: 'http://localhost:3004/fyx/sendmessage',
                        headers: {'Authorization': `Bearer ${token}`},
                        data: {
                            'tel': messageID.value
                        }
                    })
                    .then(function (response) {
                    console.log('数据', response.data);
                    })
                    .catch(function (error) {
                    console.log(error);
                    });
        }

        const logFn3 = () => {
            console.log('logFn')
            var xszID = document.getElementById('xszID');
            let fronFile = null
            if (xszID.files && xszID.files.length > 0) {
                fronFile = xszID.files[0];

                const reader = new FileReader();
        
                reader.onload = function(e) {
                    const base64String = e.target.result;

                    console.log('base64String', base64String)
                    
                    axios({
                        method: 'post',
                        url: 'http://localhost:3004/fyx/uploadIDdrivinglicense',
                        headers: {'Authorization': `Bearer ${token}`},
                        data: {
                            'image': base64String,
                            configure: {
                                side: 'face'
                            }
                        }
                    })
                    .then(function (response) {
                    console.log('数据', response.data);
                    })
                    .catch(function (error) {
                    console.log(error);
                    });
                    
                    // 显示 Base64 字符串
                    // document.getElementById('base64Output').value = base64String;
                    
                    // 显示图片预览（可选）
                    // const imgElement = document.getElementById('preview');
                    // imgElement.src = base64String;
                    // imgElement.style.display = 'block';
                };
                
                reader.onerror = function(e) {
                    console.error("File could not be read! Code " + e.target.error.code);
                };
                
                // 读取文件为 Data URL（Base64 编码）
                reader.readAsDataURL(fronFile);
            }
        }


        const logFn2 = () => {
            console.log('logFn')
            var yyzzID = document.getElementById('yyzzID');
            let fronFile = null
            if (yyzzID.files && yyzzID.files.length > 0) {
                fronFile = yyzzID.files[0];

                const reader = new FileReader();
        
                reader.onload = function(e) {
                    const base64String = e.target.result;

                    console.log('base64String', base64String)
                    
                    axios({
                        method: 'post',
                        url: 'http://localhost:3004/fyx/uploadIDbusinesslicense',
                        headers: {'Authorization': `Bearer ${token}`},
                        data: {
                            'image': base64String
                        }
                    })
                    .then(function (response) {
                    console.log('数据', response.data);
                    })
                    .catch(function (error) {
                    console.log(error);
                    });
                    
                    // 显示 Base64 字符串
                    // document.getElementById('base64Output').value = base64String;
                    
                    // 显示图片预览（可选）
                    // const imgElement = document.getElementById('preview');
                    // imgElement.src = base64String;
                    // imgElement.style.display = 'block';
                };
                
                reader.onerror = function(e) {
                    console.error("File could not be read! Code " + e.target.error.code);
                };
                
                // 读取文件为 Data URL（Base64 编码）
                reader.readAsDataURL(fronFile);
            }
        }

        const logFn = () => {
            console.log('logFn')
            var sfzID = document.getElementById('sfzID');
            let fronFile = null
            if (sfzID.files && sfzID.files.length > 0) {
                fronFile = sfzID.files[0];

                const reader = new FileReader();
        
                reader.onload = function(e) {
                    const base64String = e.target.result;

                    console.log('base64String', base64String)
                    
                    axios({
                        method: 'post',
                        url: 'http://localhost:3004/fyx/uploadIDbase64',
                        headers: {'Authorization': `Bearer ${token}`},
                        data: {
                            'image': base64String
                        }
                    })
                    .then(function (response) {
                    console.log('数据', response.data);
                    })
                    .catch(function (error) {
                    console.log(error);
                    });
                    
                    // 显示 Base64 字符串
                    // document.getElementById('base64Output').value = base64String;
                    
                    // 显示图片预览（可选）
                    // const imgElement = document.getElementById('preview');
                    // imgElement.src = base64String;
                    // imgElement.style.display = 'block';
                };
                
                reader.onerror = function(e) {
                    console.error("File could not be read! Code " + e.target.error.code);
                };
                
                // 读取文件为 Data URL（Base64 编码）
                reader.readAsDataURL(fronFile);
            }
        }

        const getData = () => {
            axios({
                method: 'get',
                url: 'http://localhost:3004/fyx/workerorder/list',
                headers: {'Authorization': `Bearer ${token}`}
            })
            .then(function (response) {
              console.log('数据', response.data);
            })
            .catch(function (error) {
            console.log(error);
            });

            axios({
                method: 'get',
                url: 'http://localhost:3004/fyx/workerorder/servicehistory',
                headers: {'Authorization': `Bearer ${token}`}
            })
            .then(function (response) {
              console.log('数据', response.data);
            })
            .catch(function (error) {
            console.log(error);
            });
        }

        // 登录接口
        axios.get('http://localhost:3004/fyx/login').then(res => {
            console.log('登录信息', res.data)
            token = res.data.data.token
            getData()
        })

    // 身份证文件上传
    const upload = () => {
        var fronID = document.getElementById('fronID');
        var endID = document.getElementById('endID');
        let fronFile = null
        let endFile = null
        if (fronID.files && fronID.files.length > 0) {
            fronFile = fronID.files[0];
        }
        if (endID.files && endID.files.length > 0) {
            endFile = endID.files[0];
        }
        if(fronFile && endFile) {
            let formdata = new FormData()
            formdata.append('frontImage', fronFile)
            formdata.append('backImage', endFile)

            axios({
                method: 'post',
                url: 'http://localhost:3004/fyx/uploadID',
                headers: {'Authorization': `Bearer ${token}`},
                data: formdata
            })
            .then(function (response) {
              console.log('数据', response.data);
              console.log('resopnese', response)
            })
            .catch(function (error) {
                console.log(error);
            });
        }
    }



    </script>
</body>
</html>